<!--
 * @description  : 仓储信息登记组件
 * @descriptionDetail: 仓储信息登记组件
 * @copyright    : 浙江烟草
 * @author       : sy
 * @create       : 2022-07-14 18:43:02
-->
<template>
  <view class="page">
    <theme-navbar :isWhite="false" title="仓储信息登记" :customBack="handlerBack">
      <view class="nav-right-icon" v-if="!isDisabled" @click="confirmBtn">
        确定
      </view>
    </theme-navbar>
    <u-form :model="storageForm" style="padding: 0px 10px;" label-position="top" ref="uForm" :error-type="['border-bottom', 'message',]">
      <u-form-item label="仓储名称" required prop="storageName" :label-width="180">
        <u-input :custom-style="valueStyle" placeholder="请输入仓储名称" :disabled="isDisabled" v-model="storageForm.storageName" />
      </u-form-item>
      <u-form-item label="仓储地址" required prop="storageAddress" :label-width="180">
        <u-input :custom-style="valueStyle" placeholder="请输入仓储地址" :disabled="isDisabled" v-model="storageForm.storageAddress" />
      </u-form-item>
    </u-form>
  </view>
</template>

<script>
import commonService from '@/service/eCigar/common.service';
import UploadImages from "@/components/upload-images.vue";
export default {
  props: {
    storageData: {
      type: Object,
      default: () => {},
    },
    recordItem: {   // 当前指标信息
      type: Object,
      default: () => {},
    },
    checkInfo: {   // 检查信息
      type: Object,
      default: () => {},
    },
    isDisabled: {   // 是否可编辑
      type: Boolean,
      default: false,
    },
  },
  data(){
    return {
      uploadFile: commonService.uploadFile,
      delUrl: commonService.deleteFile,
      uploadHeader:{
        tk: uni.getStorageSync("tk"),
        // "content-type":'application/json',
      },
      valueStyle: {
        marginRight: "5px",
      },
      storageForm:{
        uuid: "",
        storageName: "",
        storageAddress: "",
        storagePhotoUuid: "", // 仓储图片
      },
      rules:{
        storageName: [
          {
            required: true,
            message: '请输入仓储名称',
            trigger: ['change', 'blur',],
          },
        ],
        storageAddress: [
          {
            required: true,
            message: '请输入仓储地址',
            trigger: ['change', 'blur',],
          },
        ],
      },
    }
  },
  onReady() {
    this.$refs.uForm && this.$refs.uForm.setRules(this.rules);
  },
  mounted() {
    this.$refs.uForm.setRules(this.rules);
  },
  created() {
    Object.assign(this.storageForm, this.storageData, );
  },
  methods:{  
    // 确认事件
    confirmBtn(){
      this.$refs.uForm.validate(valid => {
        if (valid) { 
          this.$emit("back", this.storageForm);
          console.log('表单验证通过');
        }
      });     
    },
    handlerBack() {
      this.$emit("back", null);
    },
  },
}
</script>

<style lang="scss" scoped>
/deep/ .u-card {
  margin: 0px !important;
}
</style>
